<?php

namespace app\common\model;

use think\Model;

class ShoppingCart extends Model
{

    /** 列表
     * @param $where array
     * @param $page int
     * @param $num int
     * @param $field string
     * @return object
     */
    public static function dataList($where,$page,$num,$field="*",$order="id desc"){
        return self::where($where)
            ->field($field)
            ->page($page,$num)
            ->select();
    }

    /** 列表总数统计
     * @param $where array
     * @return int
     */
    public static function dataCount($where){
        return intval(self::where($where)->count());
    }



    public static function shopCartList($where,$page,$num,$field="s.*,p.p_name,p.inventory,p.img,p.supply_price,p.state as p_state,p.shi_type,p.inventory,p.commission_price,p.specifications,p.fs_state",$order="s.id desc"){
        return self::alias("s")
            ->leftJoin("product p","p.id=s.p_id")
            ->where($where)
            ->field($field)
            ->page($page,$num)
            ->select();
    }

    public static function shopCartListAll($where,$field="s.*,p.p_name,p.inventory,p.img,p.supply_price,p.state as p_state,p.shi_type,p.inventory,p.commission_price,p.p_num,p.specifications,p.fs_state",$order="s.id desc"){
        return self::alias("s")
            ->leftJoin("product p","p.id=s.p_id")
            ->where($where)
            ->field($field)
            ->select();
    }

    /** 列表总数统计
     * @param $where array
     * @return int
     */
    public static function shopCartListCount($where){
        return intval(self::alias("s")
            ->leftJoin("product p","p.id=s.p_id")
            ->where($where)->count());
    }

    public static function dataListAll($where,$field){
        return self::where($where)->field($field)->select();
    }

    /** 详情
     * @param $where array
     * @return object
     */
    public static function dataInfo($where){
        return self::where($where)->find();
    }


    /** 新增
     * @param $data array
     * @return int
     */
    public static function addInfo($data){
        return self::create($data);
    }

    /** 修改
     * @param $data array
     * @return bool
     */
    public static function editInfo($where,$data){
        return self::where($where)->update($data);
    }

    /** 数值增加
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      * @param $data array
     * @return int
     */
    public static function incInfo($where,$field,$num){
        return self::where($where)->inc($field,$num)->update();
    }

    /** 数值减少
     * @param $data array
     * @return int
     */
    public static function decInfo($where,$field,$num){
        return self::where($where)->dec($field,$num)->update();
    }
}